package xin.marcher.module.price.remote;

import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Component;
import xin.marcher.module.common.core.JsonResult;
import xin.marcher.module.common.enums.ProductResultEnum;
import xin.marcher.module.common.exception.BaseBizException;
import xin.marcher.module.construction.api.ProductApi;
import xin.marcher.module.construction.domain.dto.SkuDetailDTO;
import xin.marcher.module.construction.domain.request.QuerySkuListRequest;

import java.util.Collections;
import java.util.List;
import java.util.Set;

/**
 * 商品 API
 */
@Component
public class ProductRemote {
    @DubboReference(version = "1.0.0")
    private ProductApi productApi;

    /**
     * 根据skuId集合批量查询sku信息
     *
     * @param skuIds
     * @return
     */
    public List<SkuDetailDTO> listSkus(Set<String> skuIds) {
        QuerySkuListRequest queryRequest = new QuerySkuListRequest();
        queryRequest.setSkuIdSet(skuIds);
        queryRequest.setCustomResult(Collections.singletonList(ProductResultEnum.BASE.getCode()));
        JsonResult<List<SkuDetailDTO>> result = productApi.listSkus(queryRequest);

        if (!result.getSuccess()) {
            throw new BaseBizException(result.getErrorMessage(), result.getErrorCode());
        }

        return result.getData();
    }
}